﻿using System;
using System.IO;
using FunctionalCLR.Core;
using Zove.Runtime;
using FunctionalCLR.Shell;

namespace Zove.Shell.Modelling
{
    public class ValidateNode : ContextFuncNode {

        public ValidateNode()
            : base() {
            base.Value = "validate";
        }

        public override object Evaluate() {
            if (Parameters.Count == 0) {
                throw new ArgumentException(
                    "Usage: validate(modelAbosultePath)");
            }

            if (!(Parameters[0] is StringNode)) {
                throw new ArgumentException(
                    "The argument should be a string.");
            }

            try {
                IRuntimeModelLoader loader
                    = ZoveDependencyManager.Instance.RuntimeModelLoader;
                string modelName = 
                    Convert.ToString(Parameters[0].Evaluate());
                if (File.Exists(modelName)) {
                    RuntimeModel rm = loader.LoadBySource(modelName);
                } else {
                    RuntimeModel rm = loader.LoadByClassName(modelName);
                }
            } catch (Exception ex) {
                return false;
            }

            return true;
        }
    }
}
